<!--
    @description 维修工单
    @author haoyang.ding
    @date 2021-01-25
-->
<template>
  <section class="appointment-select">
    <OneTableTemplate
      ref="multipleTable"
      :dynamic-is-init-table="true"
      :dynamic-api-config="apiConfig"
      :dynamic-components="formInputs"
      :dynamic-buttons="formButtons"
      :dynamic-table-cols="tableHeader"
      :dynamic-is-show-select="false"
      :dynamic-form-fields="formField"
    />
  </section>
</template>

<script>
import OneTableTemplate from '@/components/templates/oneTable'
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import { exportExcel } from '@/utils/getTimeString'
import { vehiclePdiPriceInquirys } from '@/api/se/vehiclePdiPriceInquiry'
export default {
  name: 'RepairOrder',
  components: {
    OneTableTemplate
  },
  mixins: [oneTableWithViewTemplateMixins],
  data() {
    return {
      apiConfig: vehiclePdiPriceInquirys.workOrderList,
      formField: {
        repairOrderCode: '',
        carLicense: '',
        vin: '',
        repairMan: '',
        repairTel: '',
        custName: '',
        custTel: '',
        empName: '', // 服务顾问
        repairOrderStatus: '',
        choice: '1',
        repairTimeStart: '',
        repairTimeEnd: ''
      },
      flag: true,
      formInputs: [
        {
          compKey: 'compKey1',
          labelName: '到店日期：',
          codeField: 'repairTimeStart,repairTimeEnd',
          component: () => import('@/components/org/datePicker/datePicker'),
          dateType: 'daterange',
          isMust: true
        },
        {
          compKey: 'compKey2',
          labelName: '派工单号：',
          codeField: 'repairOrderCode',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true
        },
        {
          compKey: 'compKey3',
          labelName: '车牌号：',
          codeField: 'carLicense',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true
        },
        {
          compKey: 'compKey4',
          labelName: 'VIN码：',
          codeField: 'vin',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true
        },
        {
          compKey: 'compKey5',
          labelName: '送修人：',
          codeField: 'repairMan',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: false
        },
        {
          compKey: 'compKey6',
          labelName: '送修人电话：',
          codeField: 'repairTel',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: false
        },
        {
          compKey: 'compKey7',
          labelName: '车主姓名：',
          codeField: 'custName',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: false
        },
        {
          compKey: 'compKey8',
          labelName: '车主电话：',
          codeField: 'custTel',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: false
        },
        {
          compKey: 'compKey9',
          labelName: '服务顾问：',
          codeField: 'empName',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: false
        },
        {
          compKey: 'compKey10',
          labelName: '维修状态：',
          codeField: 'repairOrderStatus',
          component: () => import('@/components/org/commonSelect'),
          customObj: {
            api: vehiclePdiPriceInquirys.repairOrderStatus,
            selectType: '1',
            defOptionFields: ['LOOKUP_VALUE_CODE', 'LOOKUP_VALUE_NAME']
          },
          type: 'dropdownList',
          isMust: false
        }
      ],
      formButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          clickEvent: () => this.queryTable(),
          name: 'search',
          position: 'right',
          text: '查询' // "查询"
        },
        {
          compKey: 'btnKey2',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right' // 重置
        },
        {
          compKey: 'btnKey3',
          size: 'small',
          name: 'add',
          position: 'left',
          clickEvent: () => this.add(),
          text: '新增'
        },
        {
          compKey: 'btnKey4',
          size: 'small',
          clickEvent: () => this.exportExcel111(),
          name: 'export',
          position: 'left',
          text: '导出' // "导出"
        }
      ],
      tableHeader: [
        {
          prop: 'isAuthorized',
          label: '是否委外',
          hidden: true
        },

        {
          prop: 'appConfirm',
          label: '是否车主确认',
          hidden: true
        },
        {
          prop: 'controlBtn',
          label: '操作', // 操作
          codeField: 'orgName',
          align: 'center',
          width: 80,
          isComponent: true,
          comps: [
            {
              compKey: 'propKey0',
              align: 'center',
              labelName: '修改',
              codeField: 'orgName',
              clickEvent: (index) => this.modify(index),
              component: () => import('@/components/org/linkButton'),
              rowFileds: 'show:repairOrderStatusName--已作废|收款'
            },
            {
              compKey: 'propKey1',
              align: 'center',
              labelName: '查看',
              codeField: 'orgName',
              clickEvent: (index) => this.modify(index),
              component: () => import('@/components/org/linkButton'),
              rowFileds: 'show:repairOrderStatusName-已作废|收款'
            }
          ]
        },
        {
          label: '派工单号',
          prop: 'repairOrderCode',
          width: 140
        },
        {
          label: '维修状态',
          prop: 'repairOrderStatusName'
        },
        {
          label: '车主确认',
          prop: 'appConfirmName'
        },
        {
          label: '服务顾问',
          prop: 'empName'
        },
        {
          label: '创建时间',
          prop: 'createdDate',
          width: 100
        },
        {
          label: '车牌号',
          prop: 'carLicense'
        },
        {
          label: '车主姓名',
          prop: 'custName'
        },
        {
          label: '车主电话',
          prop: 'custTel',
          width: 100
        },
        {
          label: '到店时间',
          prop: 'repairTime',
          width: 100
        },
        {
          label: '预交车时间',
          prop: 'preGetDate',
          width: 100
        },
        {
          label: '送修人',
          prop: 'repairMan'
        },
        {
          label: '送修人电话',
          prop: 'repairTel',
          width: 100
        },
        {
          label: 'VIN码',
          prop: 'vin',
          width: 140
        },
        {
          label: '销售交车日期',
          prop: 'deliveryDate',
          width: 100
        }
      ]
    }
  },
  watch: {
    $route(to, from) {
      this.queryTable()
    }
  },

  methods: {
    add() {
      this.$router.push({ name: 'orderDetails', params: { add: '新增' }})
    },

    modify(index) {
      const repairOrderCode = this.$refs.multipleTable.list[index].repairOrderCode
      const dlrId = this.$refs.multipleTable.list[index].dlrId
      const repairOrderId = this.$refs.multipleTable.list[index].repairOrderId
      const updateControlId = this.$refs.multipleTable.list[index].updateControlId
      const repairOrderStatus = this.$refs.multipleTable.list[index].repairOrderStatus
      const vin = this.$refs.multipleTable.list[index].vin
      const repairOrderStatusName = this.$refs.multipleTable.list[index].repairOrderStatusName
      const appConfirm = this.$refs.multipleTable.list[index].appConfirm
      if (this.$refs.multipleTable.list[index].isAuthorized === '1') {
        this.$router.push({
          name: 'orderDetails',
          params: {
            updateControlId: updateControlId,
            repairOrderCode: repairOrderCode,
            dlrId: dlrId,
            vin: vin,
            repairOrderId: repairOrderId,
            repairOrderStatusName: repairOrderStatusName,
            repairOrderStatus: repairOrderStatus,
            appConfirm: appConfirm,
            edit: '修改'
          }
        })
      } else if (this.$refs.multipleTable.list[index].isAuthorized === '2') {
        this.$router.push({
          name: 'maintenanceOutsource',
          params: {
            updateControlId: updateControlId,
            repairOrderCode: repairOrderCode,
            dlrId: dlrId,
            vin: vin,
            repairOrderId: repairOrderId,
            repairOrderStatusName: repairOrderStatusName,
            repairOrderStatus: repairOrderStatus,
            appConfirm: appConfirm
          }
        })
      }
    },
    // 导出
    exportExcel111() {
      exportExcel(
        this.formField,
        vehiclePdiPriceInquirys.workOrderExcel.APIUrl,
        vehiclePdiPriceInquirys.workOrderExcel.ServiceCode,
        '维修工单'
      )
    }
  }
}
</script>
